<?php

namespace App\Http\Controllers\Article\Web;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Article\ArticleCategoryValidate;
use App\Http\Validate\Article\ArticleRecommendValidate;
use App\Http\Validate\Article\ArticleValidate;
use App\Models\Article\ArticleRecommendModel;
use App\Service\Article\ArticleCategoryService;
use App\Service\Article\ArticleRecommendService;
use App\Service\Article\ArticleService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class ArticleRecommendController extends BaseController
{
    /**
     * 推荐
     *
     * @return JsonResponse
     * @throws ValidationException|Exception
     */
    public function list(): JsonResponse
    {

        $list = ArticleRecommendService::list(ArticleRecommendValidate::listValidate());
        return $this->success($list);
    }

    /**
     * 添加
     *
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function add(): JsonResponse
    {
        ArticleRecommendService::add(ArticleRecommendValidate::addValidate());
        return $this->success();
    }

    /**
     * 详情
     *
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function detail()
    {
        $detail = ArticleRecommendService::detail(ArticleRecommendValidate::detailValidate());
        return $this->success($detail);
    }

    /**
     * 更新
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function update()
    {
        ArticleRecommendService::update(ArticleRecommendValidate::updateValidate());
        return $this->success();
    }

    /**
     * 更新
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function patch()
    {
        ArticleRecommendService::patch(ArticleRecommendValidate::patchValidate());
        return $this->success();
    }


    /**
     * 删除
     *
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function delete(Request $request)
    {
        ArticleRecommendService::del((int)$request->get('id'));

        return $this->success();
    }


    /**
     * 预览
     *
     * @return JsonResponse
     */
    public function preview()
    {
        $list = ArticleRecommendService::getRecommendList([
            'isActivate' => ArticleRecommendModel::ACTIVATE_ON
        ]);
        return $this->success($list);
    }
}
